<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.num" placeholder="流水号" style="width: 150px;" class="filter-item" />
      <el-input v-model="listQuery.num" placeholder="名称" style="width: 150px;" class="filter-item" />
      <el-select v-model="listQuery.proType" placeholder="财务类别" clearable style="width: 150px" class="filter-item">
        <el-option v-for="item in proTypes" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        搜索
      </el-button>
      <el-button class="filter-item" type="success" icon="el-icon-refresh-left" @click="handleReset">
        重置
      </el-button>
      <el-button class="filter-item fr" type="warning" icon="el-icon-download" @click="handleExport">
        导出
      </el-button>
    </div>

    <el-table :data="tableData" stripe max-height="600">
      <el-table-column prop="id" label="流水号" />
      <el-table-column prop="name" label="名称" />
      <el-table-column prop="num" label="分类" />
      <el-table-column prop="standard" label="收款方/付款方" />
      <el-table-column prop="price" label="类型" />
      <el-table-column prop="count" label="金额" />
      <el-table-column prop="supply_num" label="收款/收款时间" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { wareAll } from '@/api'
import Pagination from '@/components/Pagination'

export default {
  name: 'Bills',
  components: {
    Pagination
  },
  data() {
    return {
      listQuery: {
        num: '', // 采购单号
        name: '', // 产品名称
        proType: '', // 产品类别
        page: 1,
        limit: 20,
        importance: undefined,
        title: undefined,
        type: undefined
      },
      proTypes: [
        {
          id: '111',
          name: '电器'
        },
        {
          id: '222',
          name: '服装'
        }
      ],
      tableData: [],
      total: 100,
      rules: {
        type: [{ required: true, message: 'type is required', trigger: 'change' }],
        timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
        title: [{ required: true, message: 'title is required', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.inWare()
  },
  methods: {
    // 筛选
    handleFilter() {
      console.log('筛选')
    },
    // 重置
    handleReset() {
      console.log('重置')
    },
    // 入库列表
    inWare() {
      wareAll().then(res => {
        this.tableData = res.data
      }).catch(err => {
        console.log(err)
      })
    },
    // 点击导出
    handleExport() {
      console.log('导出')
    },
    // 分页事件
    getList() {
      console.log('分页事件')
      // fetchList(this.listQuery).then(response => {
      //   this.list = response.data.items
      //   this.total = response.data.total
      //
      //   // Just to simulate the time of the request
      //   setTimeout(() => {
      //     this.listLoading = false
      //   }, 1.5 * 1000)
      // })
    }
  }
}
</script>
